package com.delicious.servlet;

import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.delicious.dao.impl.MessageDaoImpl;
import com.delicious.entity.Message;

public class MessageSaveSerlvet extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String username = request.getParameter("username");
		String phone = request.getParameter("phone");
		String email = request.getParameter("email");
		String content = request.getParameter("content");
		Calendar calendar = Calendar.getInstance();  
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");  
        String strDate = simpledateformat.format(calendar.getTime());   
		Message msg = new Message(0, username, phone, email, content,strDate, 0);
		
		if(!new MessageDaoImpl().saveMessage(msg)){
			request.getSession().setAttribute("message", "添加失败");
		}
		else{
			request.getSession().setAttribute("message", "添加成功");
		}
			
		response.sendRedirect("MessageListServlet");
	}
	public static void main(String[] args) {
		Calendar calendar = Calendar.getInstance();  
        SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd");  
        String strDate = simpledateformat.format(calendar.getTime());   
        System.out.println(strDate);
	}

}
